package io.finer.erp.jeecg.bas.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.finer.erp.jeecg.bas.entity.BasMaterialCategory;
import io.finer.erp.jeecg.bas.entity.BasMeasureUnit;

/**
 * @ClassName TreeModel
 * @Description 树形下拉框使用
 * @author duanyong
 * @Date 2020-10-07 14:50:03
 * @version 1.0.0
 */
public class TreeModel implements Serializable {
	
	private static final long serialVersionUID = 4013193970046502756L;
	
	private static final String TYPE_ID = "id";
	
	private static final String TYPE_CODE = "code";

	private String key;
	
	private String title;
	
	private String slotTitle;
	
	private boolean isLeaf;
	
	private String icon;
	
	private Integer ruleFlag;
	
	private String basMaterialType;
	
	private Map<String,String> scopedSlots;
	
	private String parentId;
	
	private String label;
	
	private String value;
	
	private List<TreeModel> children;

	public TreeModel() {
		
	}
	
	public TreeModel(BasMaterialCategory category, String type) {
		this.key = category.getId();
		this.parentId = category.getPid();
		this.title = category.getName();
		this.slotTitle =  category.getName();
		if (TYPE_ID.equals(type)) {
			this.value = category.getId();
		} else if (TYPE_CODE.equals(type)) {
			this.value = category.getCode();
		}
		this.basMaterialType = category.getCode();
		this.isLeaf = !(category.getHasChild() != null && "1".equals(category.getHasChild()));
		this.label = category.getName();
		if(!isLeaf) {
			this.children = new ArrayList<TreeModel>();
		}
	}
	 
	 public TreeModel(String key,String parentId,String slotTitle,Integer ruleFlag,boolean isLeaf) {
    	this.key = key;
    	this.parentId = parentId;
    	this.ruleFlag=ruleFlag;
    	this.slotTitle =  slotTitle;
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("title", "hasDatarule");
    	this.scopedSlots = map;
    	this.isLeaf = isLeaf;
    	this.value = key;
    	if(!isLeaf) {
    		this.children = new ArrayList<TreeModel>();
    	}
    }
	 
	public TreeModel(BasMeasureUnit unit) {
		this.key = unit.getId();
		this.parentId = unit.getPid();
		this.title = unit.getName();
		this.slotTitle =  unit.getName();
		this.value = unit.getId();
		this.basMaterialType = unit.getId();
		String hasChild = unit.getHasChild();
		this.isLeaf = !(hasChild != null && "1".equals(hasChild));
		this.label = unit.getName();
		if(!isLeaf) {
			this.children = new ArrayList<TreeModel>();
		}
	}
	
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return the label
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * @param label the label to set
	 */
	public void setLabel(String label) {
		this.label = label;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	public String getSlotTitle() {
		return slotTitle;
	}

	public void setSlotTitle(String slotTitle) {
		this.slotTitle = slotTitle;
	}

	public Integer getRuleFlag() {
		return ruleFlag;
	}

	public void setRuleFlag(Integer ruleFlag) {
		this.ruleFlag = ruleFlag;
	}

	public String getBasMaterialType() {
		return basMaterialType;
	}

	public void setBasMaterialType(String basMaterialType) {
		this.basMaterialType = basMaterialType;
	}

	public Map<String, String> getScopedSlots() {
		return scopedSlots;
	}

	public void setScopedSlots(Map<String, String> scopedSlots) {
		this.scopedSlots = scopedSlots;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public List<TreeModel> getChildren() {
		return children;
	}

	public void setChildren(List<TreeModel> children) {
		this.children = children;
	}
}
